﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using AlumniProject.Framework;

namespace AlumniProject
{
    public partial class DangNhap : System.Web.UI.Page
    {
        TaiKhoanAccess tkAccess = new TaiKhoanAccess();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDangNhap_Click(object sender, EventArgs e)
        {
            DataTable dttable = tkAccess.getTaiKhoanByUserPass(txtUser.Text, txtPass.Text);

            if (dttable.Rows.Count > 0)
            {
                Session["name"] = txtUser.Text;

                Boolean isAdmin =Convert.ToBoolean(dttable.Rows[0]["IsAdmin"]);
               
                if(isAdmin){
                    Session["role"] = "admin";
                    //Response.Redirect("index.aspx");
                    Response.Redirect("indexAdmin.aspx");
                }
                else
                {
                    Session["role"] = "user";
                }
                //String text = "User: " + Session["name"].ToString() + " Role: " + Session["role"].ToString();
                //Response.Write("<script>alert('"+text+"')</script>");
                Response.Redirect("TrangChu.aspx");
                //lblmessage.Text = "User: " + Session["name"].ToString() + " Role: " + Session["role"].ToString();
            }
            else
            {
                Response.Write("<script>alert('Tên tài khoản/Mật khẩu chưa đúng')</script>");
                Session["name"] = null;
                Session["role"] = null;
            }
            
        }
    }
}